//check address is a add liquidity address function isAddLiquidity(address from, address to, address liquidityPoolAddress) external view returns (bool) { IUniswapV2Pair pool = IUniswapV2Pair(liquidityPoolAddress);
// Check if `from` is the liquidity pool contract and `to` is a user if (from == liquidityPoolAddress && !isContract(to)) { // Check if `to` holds both tokens of the pool (add liquidity) return (to == pool.token0() || to == pool.token1()); }
return false; }
//check address is remove liquidity address function isRemoveLiquidity(address from, address to, address liquidityPoolAddress) external view returns (bool) { IUniswapV2Pair pool = IUniswapV2Pair(liquidityPoolAddress);
// Check if `to` is the liquidity pool contract and `from` is a user if (to == liquidityPoolAddress && !isContract(from)) { // Check if `from` holds both tokens of the pool (remove liquidity) return (from == pool.token0() || from == pool.token1()); }
return false; }
// check address is a contract address function isContract(address addr) internal view returns (bool) { uint32 size; assembly { size := extcodesize(addr) } return (size > 0); } }
If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !